/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.ifrs.poa.control;

import br.edu.ifrs.poa.dao.UsuarioDAO;
import br.edu.ifrs.poa.model.Usuario;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.Date;
import javax.servlet.ServletException;

/**
 *
 * @author user
 */
public class CadastroUsuarioProcessor extends Processor {

    @Override
    public void execute() throws ServletException, IOException {
        getResponse().setContentType("text/html;charset=UTF-8");
        PrintWriter out = getResponse().getWriter();
        try {
            getResponse().setContentType("text/html");
            String nome = getRequest().getParameter("Nome");
            String login = getRequest().getParameter("Login");
            String senha = getRequest().getParameter("Senha");
            Date dataCriacao = new Date(System.currentTimeMillis());
            Usuario user = new Usuario();
            user.setNome(nome);
            user.setDataCriacao(dataCriacao);
            user.setLogin(login);
            user.setSenha(senha);
            UsuarioDAO.addUsuario(user);


            DateFormat df = DateFormat.getDateInstance();
            out.println();
            out.println("<html> <head> <title> Sistema de Publicação de Noticias </title> </head>");
            out.println("<body>");
            out.println("<h1> Usuário cadastrado com sucesso ! </h1>");
            out.println("Em : " + df.format(dataCriacao) + "<p>");
            out.println("<P><a href='menu.jsp'> Voltar  </a></P>");
            out.println("</body>");
            out.println("</html>");
            out.close();
        } catch (SQLException ex) {
            throw new ServletException(ex);
        } catch (ClassNotFoundException ex){
            throw new ServletException(ex);
        } 
    }
}
